class Solution(object):
    def getSumAbsoluteDifferences(self, nums):
        n = len(nums)
        prefix = [0] * n
        prefix[0] = nums[0]
        for i in range(1, n):
            prefix[i] = prefix[i - 1] + nums[i]
        out = [0] * n
        for i in range(n):
            if i == 0:
                out[i] = prefix[-1] - (n - i) * nums[i]
            else:
                out[i] = i * nums[i] - prefix[i - 1] + prefix[-1] - prefix[i - 1] - (n - i) * nums[i]
        return out